home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / News / Alexandra.0.82 / Source / rfc822realname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-30  |  1.9 KB  |  85 lines

  1. #include <string.h>
  2.  
  3. int rfc822_realname(const char *from_header,int *from,int *to)
  4. {
  5.    char *s,*e;
  6.    int i,j,z;
  7.    int a,b;
  8.  
  9.    *from=0; *to=-1;
  10.  
  11.    if((from_header!=(void *)0)&&(from_header[0]!='\0')){
  12.       if(strchr(from_header,(int)'@')==NULL){
  13.          // no regular rfc822 thing
  14.          i=0;
  15.          j=strlen(from_header)-1;
  16.          if((from_header[i]=='(')&&(from_header[j]==')')){
  17.             i++; j--;
  18.          }
  19.          *from=i; *to=j;
  20.          return 0;
  21.       }
  22.       s=strrchr(from_header,(int)'<');
  23.       e=strrchr(from_header,(int)'>');
  24.       if((s!=NULL)&&(e!=NULL)){
  25.          i=strlen(s);
  26.          j=strlen(e);
  27.          z=strlen(from_header);
  28.          if(i>j){
  29.             if(i==z){
  30.                a=1;
  31.                b=i-j-1;
  32.             }
  33.             else{
  34.                int ii;
  35.                a=0;
  36.                ii=z-i-1;
  37.                if(from_header[ii]==' ')
  38.                   ii--;
  39.                b=ii;
  40.             }
  41.             if((from_header[a]=='"')&&(from_header[b]=='"')){
  42.                a++; b--;
  43.             }
  44.             *from=a; *to=b;
  45.             return 0; 
  46.          }
  47.       }
  48.       else{
  49.          s=strchr(from_header,(int)'(');
  50.          e=strrchr(from_header,(int)')');
  51.             if(s==e-1){
  52.                int t=strlen(from_header)-strlen(s)-1;
  53.                 while(t>0 && (from_header[t]==' '))
  54.                     t--;
  55.                 if(t>0)
  56.                    *to=t;
  57.                 else
  58.                     *to=strlen(from_header);
  59.                 *from=0;
  60.                 return 0;
  61.             }
  62.          if((s!=(void *)0)&&(e!=(void *)0)){
  63.             i=strlen(s);
  64.             j=strlen(e);
  65.             z=strlen(from_header);
  66.             if(i>j+1){
  67.                a=z-i+1;
  68.                b=z-j-1;
  69.                if((from_header[a]=='"')&&(from_header[b]=='"')){
  70.                   a++; b--;
  71.                }
  72.                *from=a; *to=b;
  73.                return 0;
  74.             }
  75.          }
  76.          else{
  77.             *from=0;
  78.             *to=strlen(from_header)-1;
  79.             return 0;
  80.          }
  81.       }
  82.    }
  83.    return 0;
  84. }
  85.